home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / zip.zip / TEMPF.H < prev    next >
Text File  |  1992-09-22  |  2KB  |  55 lines

  1. /*
  2.  
  3.  Copyright (C) 1990,1991 Mark Adler, Richard B. Wales, and Jean-loup Gailly.
  4.  Permission is granted to any individual or institution to use, copy, or
  5.  redistribute this software so long as all of the original files are included
  6.  unmodified, that it is not sold for profit, and that this copyright notice
  7.  is retained.
  8.  
  9. */
  10.  
  11. /*
  12.  *  tempf.h by Mark Adler.
  13.  */
  14.  
  15. /* These "t" functions behave like their "f" counterparts, except that
  16.    topen() takes one character to (possibly) be used in a temporary file
  17.    name, twrite() can create a temporary file, and tclose() will delete
  18.    the temporary file, if any.  tnew() is only defined for use in the
  19.    tputc() macro.  It should not be called explicitly.  These functions
  20.    use the type tFILE instead of FILE to point to a file descriptor. */
  21.  
  22. #if !defined(OS2) && (defined(M_I86CM) || defined(__COMPACT__))
  23. #   define TMPSIZ  0x8000  /* memory portion of temporary files */
  24.     /* The MSDOS compact model is to be used only for processing a large
  25.      * number of files. In this case we try to reduce the memory requirements.
  26.      * You can reduce TMPSIZ to 16384 or 8192 if 32K is still too large,
  27.      * but the resulting code will be slower.
  28.      */
  29. #else
  30. #   define TMPSIZ  0xe000  /* memory portion of temporary files */
  31. #endif
  32.  
  33. typedef struct {
  34.   char far *b;          /* memory part of file */
  35.   unsigned p;           /* current read/write pointer for memory part */
  36.   unsigned m;           /* bytes in memory part */
  37.   int c;                /* character to use in spill file name */
  38.   FILE *f;              /* spill file pointer or NULL*/
  39.   char *n;              /* spill file name if f not NULL */
  40. } tFILE;
  41.  
  42. tFILE *topen OF((int));
  43. int tnew OF((tFILE *));
  44. unsigned twrite OF((char *, unsigned, unsigned, tFILE *));
  45. int tflush OF((tFILE *));
  46. void trewind OF((tFILE *));
  47. unsigned tread OF((char *, unsigned, unsigned, tFILE *));
  48. int terror OF((tFILE *));
  49. int teof OF((tFILE *));
  50. int tclose OF((tFILE *));
  51.  
  52. #define tputcm(c,t) ((t)->b[(t)->p++]=(c),(t)->m<(t)->p?((t)->m=(t)->p):0,c)
  53. #define tputcf(c,t) ((t)->f==NULL?(tnew(t)?-1:putc(c,(t)->f)):putc(c,(t)->f))
  54. #define tputc(c,t) ((t)->p<TMPSIZ?(int)tputcm(c,t):tputcf(c,t))
  55.